<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Props</title>
</head>
<body>
    <div id="test"></div>
    <div id="test1"></div>
    <div id="test2"></div>
    <!-- 准备好一个容器-->
    <div id="test"></div>
    <!--引入react核心库-->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!--引入react.dom 用于支持react操作dom-->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!--引入bable 用于将jsx转换为js-->
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <!--引入propstypes 用于对props进行限制-->
    <script type="text/javascript" src="../js/prop-types.js"></script>
    <script type="text/babel">
    //创建组件
    class Person extends React.Component{
        render(){
            return(
                <ul>
                    <li>姓名：{this.props.name}</li>
                    <li>性别：{this.props.sex}</li>
                    <li>年龄：{this.props.age}</li>
                </ul>
            )
        }
    }
    //对标签属性的类型 必要性进行限制
    Person.propTypes={
        name:PropTypes.string.isRequired,
        sex:PropTypes.string,
        age:PropTypes.number,
    }
    //默认值
    Person.defaultProps={
        sex:'男',
        age:19
    }
    //渲染组件到页面
    ReactDOM.render(<Person name="cy" sex="男" age="18" />,document.getElementById('test'));
    ReactDOM.render(<Person name="cwt" sex="女"  />,document.getElementById('test1'));
    const p={name:'jy',age:30};
    ReactDOM.render(<Person {...p}/>,document.getElementById('test2'));
    </script>
</body>
</html>